package org.example.demo.controller;

import org.example.demo.entity.District;
import org.example.demo.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dis")
public class DisController {
    @Autowired
    private DistrictService districtService;

    @GetMapping
    public List<District> getAll(){
        return districtService.getAll();
    }

    @GetMapping("/{id}")
    public District get(@PathVariable Integer id){
        return districtService.get(id);
    }

    @PostMapping
    public int add(@RequestBody District district){
        return districtService.add(district);
    }

    @DeleteMapping("/{id}")
    public int del(@PathVariable Integer id){
        return districtService.del(id);
    }

    @PutMapping
    public int update(@RequestBody District district){
        return districtService.update(district);
    }
}
